package com.dementors.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.dementors.R;
import com.dementors.base.BaseActivity;
import com.dementors.utils.SPUtils;

public class SplashActivity extends BaseActivity {

  private static final int WHAT_MESSAGE_1 = 1;
  private ImageView iv_splash;

  @Override protected int provideContentViewId() {
    return R.layout.activity_splash;
  }

  @Override protected void initView() {
    iv_splash= (ImageView) findViewById(R.id.iv_splash);

  }

  @Override protected void setListener() {

  }

  @Override protected void initData() {
    Animation anim= AnimationUtils.loadAnimation(this,R.anim.animator_splash) ;
    iv_splash.setAnimation(anim);
    initSplash();
  }

  private void initSplash() {
    new Handler() {

      @Override public void handleMessage(Message msg) {
        super.handleMessage(msg);
        if ((boolean) SPUtils.get(SplashActivity.this, "IS_FIRST", true)) {
          startActivity(new Intent(SplashActivity.this, GuideActivity.class));
          SPUtils.put(SplashActivity.this, "IS_FIRST", false);
          SplashActivity.this.finish();
        } else {
          startActivity(new Intent(SplashActivity.this, MainActivity.class));
          SplashActivity.this.finish();
        }
      }
    }.sendEmptyMessageDelayed(WHAT_MESSAGE_1, 3000);
  }

  @Override protected void getIntentData(Bundle saveInstance) {

  }

  @Override public void onClick(View v) {

  }
}
